#ifndef __TOYM__BASE__CURRECT_THREAD_H__
#define __TOYM__BASE__CURRECT_THREAD_H__
#include <sys/types.h>
#include <cstdio>

namespace toym
{

class CurrectThread {
public:
    static 
    void setThreadName(const char* name);
    static
    char* getThreadName();

    static
    const char* getTidStr() {
        if (nullptr == pTidStr) {
            std::snprintf(tidStr, sizeof(tidStr), "%d", getTid());
            pTidStr = tidStr;
        }
        return pTidStr;
    }

    static
    pid_t getTid();

    static 
    void saveErrno(int eno) {
        s_err = eno;
    }

    static
    int getErrno() {
        return s_err;
    }
private:
    static thread_local char threadName[16];
    static thread_local char tidStr[11];
    static thread_local const char* pTidStr;
    static thread_local pid_t tid;
    static thread_local int s_err;
};

} // namespace toym


#endif //__TOYM__BASE__CURRECT_THREAD_H__